package com.zbkj.client.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zbkj.client.config.ClientTokenComponent;
import com.zbkj.client.task.VideoTemplateUpdateStatusTask;
import com.zbkj.client.utils.EmojiFilterUtil;
import com.zbkj.client.utils.FileUtil;
import com.zbkj.common.model.assets.Material;
import com.zbkj.common.model.client.agent.SpecialHotTopic;
import com.zbkj.common.model.client.agent.ThirdHot;
import com.zbkj.common.model.client.agent.UserSpecialTopicCategory;
import com.zbkj.common.model.client.agent.WeekTask;
import com.zbkj.common.model.client.digital.CustomDigitalPerson;
import com.zbkj.common.model.client.digital.DpVoice;
import com.zbkj.common.model.client.digital.PublicDigitalPerson;
import com.zbkj.common.model.client.workbench.*;
import com.zbkj.common.request.client.BatchDeleteRequest;
import com.zbkj.common.request.client.ReplacePicRequest;
import com.zbkj.common.request.client.VideoTemplateRequest;
import com.zbkj.common.response.ClientLoginResponse;
import com.zbkj.common.response.client.VideoSplitResponse;
import com.zbkj.common.response.client.VideoSubtitleResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.common.utils.OssUtil;
import com.zbkj.service.service.*;
import com.zbkj.client.service.VideoServiceCommon;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.concurrent.CompletableFuture;

@Slf4j
@RestController
@RequestMapping("/api/client/workbench")
public class VideoController {

    @Autowired
    private ClientTokenComponent clientTokenComponent;

    @Autowired
    private VideoSplitService videoSplitService;

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private VideoTemplateUpdateStatusTask videoTemplateUpdateStatusTask;


    @Autowired
    private VideoServiceCommon videoServiceCommon;

    @Autowired
    private VideoSubtitleService videoSubtitleService;

    @Autowired
    private VideoSplitUrlHistoryService videoSplitUrlHistoryService;

    @Autowired
    private VideoTemplateFinalService videoTemplateFinalService;

    @Autowired
    private VideoTemplateConfigService videoTemplateConfigService;

    @Autowired
    private DpVoiceService dpVoiceService;

    @Autowired
    private UserSpecialTopicCategoryService userTopicCategoryService;

    @Autowired
    private SpecialHotTopicService specialHotTopicService;

    @Autowired
    private WeekTaskService weekTaskService;

    @Autowired
    private ThirdHotService thirdHotService;

    @Value("${workbench.video-split}")
    private String videoSplitBaseUrl;

    @Value("${workbench.video-real-url}")
    private String videoRealInfoBaseUrl;

    private String videoSplitUrl = "/api/v1/video/dismantle";
    private String douyinRealInfoUrl = "/api/hybrid/video_data";


    /**
     * 选题热榜配置列表
     * @param httpRequest
     * @return
     */
    @GetMapping("/getHotConfigList")
    public CommonResult<List<Map<String, String>>> getHotConfigList(HttpServletRequest httpRequest) {

        Integer userId = clientTokenComponent.getLoginUser(httpRequest);
        String token = httpRequest.getHeader("token");
        ClientLoginResponse userInfo = clientTokenComponent.getUserInfo(userId, token);
        Integer merId = userInfo.getMerId();

        List<Map<String, String>> hostConfigList = new ArrayList<>();

        HashMap<String, String> douyinMap = new HashMap<>();
        douyinMap.put("name", "抖音热搜榜");
        douyinMap.put("source", "douyin");
        douyinMap.put("ico", "https://vision-smart.oss-cn-shanghai.aliyuncs.com/template/ico/douyin.png");
        hostConfigList.add(douyinMap);

        UserSpecialTopicCategory categorybyUserId = userTopicCategoryService.getByUserId(userId);
        if (categorybyUserId != null) {
            List<String> categorys = categorybyUserId.getCategorys();
            List<String> lastTwoCategorys = categorys.size() > 3 ? categorys.subList(categorys.size() - 3, categorys.size()) : categorys;
            for (String category : lastTwoCategorys) {
                HashMap<String, String> hashMap = new HashMap<>();
                hashMap.put("name", category);
                hashMap.put("source", category);
                if ("轻度营销类".equals(category)) {
                    hashMap.put("ico", "https://vision-smart.oss-cn-shanghai.aliyuncs.com/template/ico/markting.png");
                }else{
                    hashMap.put("ico", "https://vision-smart.oss-cn-shanghai.aliyuncs.com/template/ico/special.png");
                }

                hostConfigList.add(hashMap);
            }
        }

//        HashMap<String, String> hashMap = new HashMap<>();
//        hashMap.put("name", "抖音热搜榜");
//        hashMap.put("source", "douyin");
//        hashMap.put("ico", "https://vision-smart.oss-cn-shanghai.aliyuncs.com/template/ico/douyin.png");
//
//        HashMap<String, String> hashMap1 = new HashMap<>();
//        hashMap1.put("name", "微博热搜榜");
//        hashMap1.put("source", "weibo");
//        hashMap1.put("ico", "https://vision-smart.oss-cn-shanghai.aliyuncs.com/template/ico/weibo.png");
//
//        hostConfigList.add(hashMap);
//        hostConfigList.add(hashMap1);



        return CommonResult.success(hostConfigList);
    }

    /**
     * 选题热榜列表
     * @param page
     * @param pageSize
     * @param httpRequest
     * @return
     */
    @GetMapping("/getHotList")
    public CommonResult<IPage<?>> getHotList(@RequestParam(value = "page", defaultValue = "1") int page,
                                                             @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
                                                             @RequestParam(value = "source", required = false) String source,
                                                             HttpServletRequest httpRequest) {

        Integer userId = clientTokenComponent.getLoginUser(httpRequest);

        if ("douyin".equals(source)) {
            Page<ThirdHot> pageParam = new Page<>(page, pageSize);
            QueryWrapper<ThirdHot> wrapper = new QueryWrapper<>();
            wrapper.eq("is_del", 0)
                    .eq("source", source)
                    .orderByDesc("create_time");

            IPage<ThirdHot> res = thirdHotService.page(pageParam, wrapper);
            return CommonResult.success(res);
        }else{
            Page<SpecialHotTopic> pageParam = new Page<>(page, pageSize);
            QueryWrapper<SpecialHotTopic> wrapper = new QueryWrapper<>();
            wrapper.eq("is_del", 0)
                    .eq("user_id", userId)
                    .eq("category", source)
                    .orderByDesc("create_time");

            IPage<SpecialHotTopic> res = specialHotTopicService.page(pageParam, wrapper);
            return CommonResult.success(res);
        }
//        return CommonResult.success(res);
    }

    /**
     * 获取视频拆分列表
     * @param page
     * @param pageSize
     * @param httpRequest
     * @return
     */
    @GetMapping("/getVideoSplitList")
    public CommonResult<IPage<VideoSplit>> getVideoSplitList(@RequestParam(value = "page", defaultValue = "1") int page,
                                                             @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
                                                             @RequestParam(value = "source", required = false) String source,
                                                             HttpServletRequest httpRequest) {

        Integer userId = clientTokenComponent.getLoginUser(httpRequest);

        Page<VideoSplit> pageParam = new Page<>(page, pageSize);
        QueryWrapper<VideoSplit> wrapper = new QueryWrapper<>();
        wrapper.eq("is_del", 0)
                .eq("user_id", userId)
                .orderByDesc("create_time");
        if (source != null && !source.isEmpty()) {
            wrapper.eq("source", source);
        }
        IPage<VideoSplit> res = videoSplitService.page(pageParam, wrapper);

        return CommonResult.success(res);
    }

    /**
     * 视频拆解接口
     * @param params
     * @param httpRequest
     * @return
     */
    @PostMapping("/videoSplit")
    public CommonResult<?> videoSplit(@RequestBody Map<String, Object> params, HttpServletRequest httpRequest) {
        Integer materialId = (Integer) params.get("materialId");
        String videoUrl = (String) params.get("videoUrl");
        String type = (String) params.get("type");

        Integer userId = clientTokenComponent.getLoginUser(httpRequest);
        String token = httpRequest.getHeader("token");
        ClientLoginResponse userInfo = clientTokenComponent.getUserInfo(userId, token);
        Integer merId = userInfo.getMerId();

        //根据传入的参数，如果是视频链接，则需要先保存一份到OSS
        String result = videoServiceCommon.VideoSplit(type, videoUrl, materialId, userId, merId);

        Map<Object, Object> data = new HashMap<>();
        data.put("linkId", result);

        return CommonResult.success(data);
    }

    /**
     * 获取拆解视频详情
     * @param id
     * @return
     */
    @GetMapping("/getVideoSplitDetail")
    public CommonResult<?> getVideoSplitDetail(@RequestParam("id") Integer id) {
        VideoSplit videoSplit = videoSplitService.getById(id);
        if (videoSplit == null) {
            return CommonResult.failed("未找到对应的视频拆解记录");
        }
        //查找历史记录，将OSS地址返回
        VideoSplitUrlHistory videoSplitUrlHistory = videoSplitUrlHistoryService.getById(videoSplit.getHistoryId());

        VideoSplitResponse response = new VideoSplitResponse();
        BeanUtils.copyProperties(videoSplit, response);
        response.setOssUrl(videoSplitUrlHistory.getOssUrl());
        response.setAuthor(videoSplitUrlHistory.getAuthor());
        response.setCollectCount(videoSplitUrlHistory.getCollectCount());
        response.setCommentCount(videoSplitUrlHistory.getCommentCount());
        response.setDiggCount(videoSplitUrlHistory.getDiggCount());

        return CommonResult.success(response);
    }

    /**
     * 删除视频拆解记录
     * @param request 包含id的JSON参数
     * @return 删除结果
     */
    @PostMapping("/delVideoSplit")
    public CommonResult<?> delVideoSplit(@RequestBody BatchDeleteRequest request) {
        try {
            // 从JSON参数中获取id
            List<Integer> ids = request.getIds();
            if (ids == null || ids.isEmpty()) {
                return CommonResult.failed("请选择要删除的视频拆解记录");
            }

            // 根据id查询记录是否存在
//            VideoSplit videoSplit = videoSplitService.getById(id);
//            if (videoSplit == null || videoSplit.getIsDel() == 1) {
//                return CommonResult.failed("记录不存在");
//            }

            for (Integer id : ids) {
                try {
                    videoSplitService.removeById(id);
                } catch (Exception e) {
                    // 记录错误但继续处理其他ID
                    log.error("删除视频拆解记录ID " + id + " 失败: " + e.getMessage());
                }
            }

            return CommonResult.success("删除成功");

            // 软删除记录
//            videoSplit.setIsDel(1);
//            videoSplit.setUpdateTime(new Date());
//            boolean updateResult = videoSplitService.removeById(id);

//            if (!updateResult) {
//                return CommonResult.failed("删除失败");
//            }

            // 删除历史OSS资源
        } catch (Exception e) {
            log.error("删除视频拆解记录异常", e);
            return CommonResult.failed("删除失败: " + e.getMessage());
        }
    }

    /**
     * 获取真实信息
     * @param url
     * @return
     */
    @GetMapping("/getVideoRealInfo")
    public CommonResult<?> getVideoRealInfo(@RequestParam("url") String url) {
        try {
            Map<String, Object> videoData = videoServiceCommon.getVideoRealInfo(url);
            return CommonResult.success(videoData);
        } catch (IllegalArgumentException e) {
            return CommonResult.failed(e.getMessage());
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage() != null ? e.getMessage() : "获取视频真实信息失败");
        }
    }

    /**
     * 获取视频字幕详情
     * @param id 字幕ID
     * @return 视频字幕详情
     */
    @GetMapping("/getVideoSubtitleDetail")
    public CommonResult<?> getVideoSubtitleDetail(@RequestParam("id") Integer id) {
        VideoSubtitle videoSubtitle = videoSubtitleService.getById(id);
        if (videoSubtitle == null) {
            return CommonResult.failed("未找到对应的视频字幕记录");
        }

        //查找历史记录，将OSS地址返回
        VideoSplitUrlHistory videoSplitUrlHistory = videoSplitUrlHistoryService.getById(videoSubtitle.getHistoryId());

        VideoSubtitleResponse response = new VideoSubtitleResponse();
        BeanUtils.copyProperties(videoSubtitle, response);
        response.setOssUrl(videoSplitUrlHistory.getOssUrl());
        response.setAuthor(videoSplitUrlHistory.getAuthor());
        response.setCollectCount(videoSplitUrlHistory.getCollectCount());
        response.setCommentCount(videoSplitUrlHistory.getCommentCount());
        response.setDiggCount(videoSplitUrlHistory.getDiggCount());

        return CommonResult.success(response);
    }

    /**
     * 获取视频字幕
     * @param params
     * @param httpRequest
     * @return
     */
    @PostMapping("/videoSubtitle")
    public CommonResult<?> videoSubtitle(@RequestBody Map<String, Object> params, HttpServletRequest httpRequest) {
        Integer materialId = (Integer) params.get("materialId");
        String videoUrl = (String) params.get("videoUrl");
        String type = (String) params.get("type");

        Integer userId = clientTokenComponent.getLoginUser(httpRequest);
        String token = httpRequest.getHeader("token");
        ClientLoginResponse userInfo = clientTokenComponent.getUserInfo(userId, token);
        Integer merId = userInfo.getMerId();

        //根据传入的参数，如果是视频链接，则需要先保存一份到OSS
        String result = videoServiceCommon.VideoSubtitle(type, videoUrl, materialId, userId, merId);

        Map<Object, Object> data = new HashMap<>();
        data.put("linkId", result);

        return CommonResult.success(data);
    }

    /**
     * 获取视频拆分列表
     * @param page
     * @param pageSize
     * @param httpRequest
     * @return
     */
    @GetMapping("/getVideoSubtitleList")
    public CommonResult<IPage<VideoSubtitle>> getVideoSubtitleList(@RequestParam(value = "page", defaultValue = "1") int page,
                                                             @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
                                                             @RequestParam(value = "source", required = false) String source,
                                                             HttpServletRequest httpRequest) {

        Integer userId = clientTokenComponent.getLoginUser(httpRequest);

        Page<VideoSubtitle> pageParam = new Page<>(page, pageSize);
        QueryWrapper<VideoSubtitle> wrapper = new QueryWrapper<>();
        wrapper.eq("is_del", 0)
                .eq("user_id", userId)
                .orderByDesc("create_time");
        if (source != null && !source.isEmpty()) {
            wrapper.eq("source", source);
        }
        IPage<VideoSubtitle> res = videoSubtitleService.page(pageParam, wrapper);


        return CommonResult.success(res);
    }



    /**
     * 删除视频转文案记录
     * @param request 包含id的JSON参数
     * @return 删除结果
     */
    @PostMapping("/delVideoSubtitle")
    public CommonResult<?> delVideoSubtitle(@RequestBody BatchDeleteRequest request) {
        try {
            // 从JSON参数中获取id
            List<Integer> ids = request.getIds();
            if (ids == null || ids.isEmpty()) {
                return CommonResult.failed("请选择要删除的视频字幕记录");
            }

            for (Integer id : ids) {
                try {
                    videoSubtitleService.removeById(id);
                } catch (Exception e) {
                    // 记录错误但继续处理其他ID
                    log.error("删除视频拆解记录ID " + id + " 失败: " + e.getMessage());
                }
            }

            return CommonResult.success("删除成功");
        } catch (Exception e) {
            log.error("删除视频拆解记录异常", e);
            return CommonResult.failed("删除失败: " + e.getMessage());
        }
    }

    /**
     * 模板成片-最终合成
     * @param videoTemplateRequest
     * @return
     */
    @PostMapping("/videoTemplateCreate")
    public CommonResult<?> videoTemplateCreate(@RequestBody VideoTemplateRequest videoTemplateRequest,
                                              HttpServletRequest httpRequest) {
        Integer userId = clientTokenComponent.getLoginUser(httpRequest);
        String token = httpRequest.getHeader("token");
        ClientLoginResponse userInfo = clientTokenComponent.getUserInfo(userId, token);
        Integer merId = userInfo.getMerId();

        //调用agent返回
        VideoTemplateFinal videoTemplateFinal = videoServiceCommon.videoTemplateCommon(videoTemplateRequest, userId, merId);

        return CommonResult.success("成功");
    }

    /**
     * 模板成片-最终合成
     * @param videoTemplateRequest
     * @return
     */
    @PostMapping("/videoTemplateEdit")
    public CommonResult<?> videoTemplateEdit(@RequestBody VideoTemplateRequest videoTemplateRequest,
                                               HttpServletRequest httpRequest) {
        Integer userId = clientTokenComponent.getLoginUser(httpRequest);
        String token = httpRequest.getHeader("token");
        ClientLoginResponse userInfo = clientTokenComponent.getUserInfo(userId, token);
        Integer merId = userInfo.getMerId();

        //调用agent返回
        videoServiceCommon.videoTemplateEdit(videoTemplateRequest, userId, merId);

        return CommonResult.success("成功");
    }

    /**
     * 模板成片-编辑的时候合成预览
     * @param videoTemplateRequest
     * @param
     * @return
     */
    @PostMapping("/videoTemplateEditPreview")
    public CommonResult<VideoTemplateFinal> videoTemplateEditPreview(@RequestBody VideoTemplateRequest videoTemplateRequest,
                                                                 HttpServletRequest httpRequest) {

        Integer userId = clientTokenComponent.getLoginUser(httpRequest);
        String token = httpRequest.getHeader("token");
        ClientLoginResponse userInfo = clientTokenComponent.getUserInfo(userId, token);
        Integer merId = userInfo.getMerId();

        Map<String, Object> result = videoServiceCommon.videoTemplatePreview(videoTemplateRequest, userId, merId);
        String msg = (String) result.get("msg");
        if (msg != null && !msg.isEmpty()){
            return CommonResult.failed(msg);
        }

        VideoTemplateFinal resultData = videoTemplateFinalService.getById((Integer)result.get("id"));

        return CommonResult.success(resultData);
    }

    /**
     * 模板成片-合成预览
     * @param videoTemplateRequest
     * @param
     * @return
     */
    @PostMapping("/videoTemplatePreview")
    public CommonResult<VideoTemplateFinal> videoTemplatePreview(@RequestBody VideoTemplateRequest videoTemplateRequest,
                                              HttpServletRequest httpRequest) {

        Integer userId = clientTokenComponent.getLoginUser(httpRequest);
        String token = httpRequest.getHeader("token");
        ClientLoginResponse userInfo = clientTokenComponent.getUserInfo(userId, token);
        Integer merId = userInfo.getMerId();

        Map<String, Object> result = videoServiceCommon.videoTemplatePreview(videoTemplateRequest, userId, merId);
        String msg = (String) result.get("msg");
        if (msg != null && !msg.isEmpty()){
            return CommonResult.failed(msg);
        }

        VideoTemplateFinal resultData = videoTemplateFinalService.getById((Integer)result.get("id"));

        return CommonResult.success(resultData);
    }

    /**
     * 模板成片-替换画中画素材
     * @param replacePicRequest
     * @param
     * @return
     */
    @PostMapping("/replacePic")
    public CommonResult<?> replacePic(@RequestBody ReplacePicRequest replacePicRequest,
                                                                 HttpServletRequest httpRequest) {

        Integer userId = clientTokenComponent.getLoginUser(httpRequest);
        String token = httpRequest.getHeader("token");
        ClientLoginResponse userInfo = clientTokenComponent.getUserInfo(userId, token);
        Integer merId = userInfo.getMerId();


        Boolean resultData = videoServiceCommon.replacePic(replacePicRequest);

        if (resultData == true){
            return CommonResult.success("素材处理成功");
        }

        return CommonResult.failed("素材处理失败");
    }


    /**
     * 获取模板视频列表-成片列表
     * @param page
     * @param pageSize
     * @param httpRequest
     * @return
     */
    @GetMapping("/getVideoTemplateList")
    public CommonResult<IPage<VideoTemplateFinal>> getVideoTemplateList(@RequestParam(value = "page", defaultValue = "1") int page,
                                                             @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
                                                             @RequestParam(value = "parentId", required = false) Integer parentId,
                                                             HttpServletRequest httpRequest) {

        Integer userId = clientTokenComponent.getLoginUser(httpRequest);

        Page<VideoTemplateFinal> pageParam = new Page<>(page, pageSize);
        QueryWrapper<VideoTemplateFinal> wrapper = new QueryWrapper<>();
        wrapper.eq("is_del", 0)
                .eq("user_id", userId)
                .orderByDesc("create_time");

        Integer parId = parentId != null ? parentId : 0;
        wrapper.eq("parent_id", parId);

        IPage<VideoTemplateFinal> res = videoTemplateFinalService.page(pageParam, wrapper);

        return CommonResult.success(res);
    }

    /**
     * 获取模板视频详情
     * @param id
     * @return
     */
    @GetMapping("/getVideoTemplateDetail")
    public CommonResult<VideoTemplateFinal> getVideoTemplateDetail(@RequestParam(value = "id", required = false) int id,
                                                                     HttpServletRequest httpRequest) {
        VideoTemplateFinal byId = videoTemplateFinalService.getById(id);
        return CommonResult.success(byId);
    }

    @ApiOperation(value = "批量删除生成的视频模板（软删除）")
    @PostMapping("/delVideoTemplate")
    public CommonResult<Map<String, Object>> delVideoTemplate(@RequestBody BatchDeleteRequest request, HttpServletRequest httpRequest) {
        List<Integer> ids = request.getIds();
        if (ids == null || ids.isEmpty()) {
            return CommonResult.failed("请选择要删除的视频");
        }

        Integer userId = clientTokenComponent.getLoginUser(httpRequest);
        if (userId == null) {
            return CommonResult.failed("用户未登录");
        }

        // 校验所有id对应的记录
        for (Integer id : ids) {
            VideoTemplateFinal videoTemplateFinal = videoTemplateFinalService.getById(id);
            if (videoTemplateFinal == null || videoTemplateFinal.getIsDel() == null || videoTemplateFinal.getIsDel() != 0) {
                return CommonResult.failed("视频ID " + id + " 不存在或已被删除");
            }
            if (!userId.equals(videoTemplateFinal.getUserId())) {
                return CommonResult.failed("无权操作素材ID " + id);
            }
        }

        boolean result = videoServiceCommon.batchDelVideo(ids);
        Map<String, Object> data = new HashMap<>();
        data.put("result", result ? 1 : 0);
        return CommonResult.success(data);
    }

    /**
     * 获取模板配置列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/getTemplateConfigList")
    public CommonResult<IPage<VideoTemplateConfig>> getTemplateConfigList(@RequestParam(value = "page", defaultValue = "1") int page,
                                                                               @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
                                                                               HttpServletRequest httpRequest) {

        Page<VideoTemplateConfig> pageParam = new Page<>(page, pageSize);
        IPage<VideoTemplateConfig> result = videoTemplateConfigService.lambdaQuery()
                .eq(VideoTemplateConfig::getIsDel, 0)
                .orderByDesc(VideoTemplateConfig::getCreateTime)
                .page(pageParam);
        return CommonResult.success(result);
    }

    /**
     * 获取模板配置列表
     * @param id
     * @return
     */
    @GetMapping("/getTemplateConfigDetail")
    public CommonResult<VideoTemplateConfig> getTemplateConfigDetail(@RequestParam(value = "id", required = false) int id,
                                                                               HttpServletRequest httpRequest) {
        VideoTemplateConfig byId = videoTemplateConfigService.getById(id);
        return CommonResult.success(byId);
    }

    /**
     * 获取真实信息
     * @param url
     * @return
     */
    @PostMapping(value = "/test", consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
    public String test(@RequestParam("content") String content) {
        String filteredContent = EmojiFilterUtil.removeEmojis(content);
        return filteredContent;
    }
    
    @PostMapping("/testJson")
    public String testJson(@RequestBody Map<String, Object> param) {
        String content = (String) param.get("content");
        String filteredContent = EmojiFilterUtil.removeEmojis(content);
        return filteredContent;
    }

    /**
     * 测试高亮文本处理
     * @param content 原始内容
     * @param hig 高亮关键词列表
     * @return 处理后的高亮文本
     */
    @PostMapping("/test1")
    public String test1(@RequestParam("content") String content, @RequestParam("hig") List<String> hig) {
        VideoTemplateConfig videotemplateconfig = new VideoTemplateConfig();
        videotemplateconfig.setId(1);

        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("title_color", "#466ef3");
        hashMap.put("picture_ratio", "16/9");
        videotemplateconfig.setConfig(hashMap);
        videoTemplateConfigService.updateById(videotemplateconfig);

        return content;
    }
} 